package com.xiaobai.zhuangxiuguanjia.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xiaobai.zhuangxiuguanjia.R;

import java.util.List;

/**
 * Created by gggcccwww on 2015/6/17.
 */
public class GridViewAdapter extends BaseAdapter{
    private Context context;
    private List<String> list;


    public GridViewAdapter(Context context, List<String> list) {
        super();
        this.context = context;
        this.list = list;
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }
    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list.get(position);
    }
    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView ==null)
        {
            convertView = LayoutInflater.from(context).inflate(R.layout.gridview_layout, null);
            viewHolder = new ViewHolder();
            viewHolder.textView = (TextView) convertView.findViewById(R.id.gridview_diquanniu);

            convertView.setTag(viewHolder);
        }
        else
            viewHolder = (ViewHolder) convertView.getTag();

        viewHolder.textView.setText(list.get(position));
        return convertView;
    }
    class ViewHolder
    {
        TextView textView;
    }

}
